package com.wanglibao.woodtrade.woodtrade.ui.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.wanglibao.woodtrade.woodtrade.R;
import com.wanglibao.woodtrade.woodtrade.ui.activity.InformationDetailActivity;
import com.wanglibao.woodtrade.woodtrade.ui.fragment.adapter.ItemLvInformationAvtivityAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 资讯
 * Created by lugg on 2016/5/10.
 */
public class InformationFragment extends BaseFragment implements AdapterView.OnItemClickListener {

    @Bind(R.id.tv_commonTitle_title)
    TextView mTvCommonTitleTitle;
    @Bind(R.id.tv_commonTitle_back)
    TextView mTvCommonTitleBack;
    @Bind(R.id.tv_commonTitle_right)
    TextView mTvCommonTitleRight;
    @Bind(R.id.lv_information_activity)
    ListView mLvInformationActivity;
    //==================================
    Context mContext;
    ItemLvInformationAvtivityAdapter mAdapter;
    List<String> imageUrls=new ArrayList<>();

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        View view = inflater.inflate(R.layout.fragment_information, container, false);
        ButterKnife.bind(this, view);
        mContext=this.getActivity();
        initData();
        return view;
    }

    private void initData() {
        imageUrls.add("http://easyread.ph.126.net/LHZYBloTRqECwKQK3h5kSg==/7916834464196635983.jpg");
        imageUrls.add("http://www.wmgjad.com/upload/2014/09/23/14114461980345em267.jpg");
        imageUrls.add("http://e.hiphotos.baidu.com/image/pic/item/5bafa40f4bfbfbedef57ab457ff0f736afc31ff9.jpg");
        imageUrls.add("http://imgtest.meiliworks.com/pic/_o/55/3a/c5f334a8468fda3b1faeb446b08f_640_960.c1.jpg?frm=out_pic");
        imageUrls.add("http://img1.gtimg.com/ent/pics/hv1/196/22/1963/127649881.png");
        mTvCommonTitleBack.setText("");
        mTvCommonTitleTitle.setText("资讯");
        mAdapter=new ItemLvInformationAvtivityAdapter(mContext,imageUrls);
        mLvInformationActivity.setAdapter(mAdapter);
        mLvInformationActivity.setOnItemClickListener(this);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void setMenuVisibility(boolean menuVisible) {
        super.setMenuVisibility(menuVisible);
        if (this.getView() != null)
            this.getView().setVisibility(menuVisible ? View.VISIBLE : View.GONE);
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Intent intent=new Intent(mContext, InformationDetailActivity.class);
        intent.putExtra("URl",imageUrls.get(position));
        startActivity(intent);
    }
}
